package com.neusoft.elm.controller;

import com.neusoft.elm.po.User;
import com.neusoft.elm.service.UserService;
import com.neusoft.elm.service.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;

public class UserController {
    UserService userService=new UserServiceImpl();
    //其实这里我有一个疑问:他为啥不能直接用userdao,
    //反倒需要UserServiceImpl这个实体类里面的一个方法再去和userDao创造联系
    //一会儿试试将UserService改成UserDao
    //整个过程，前端传入数据，由request.getParameter获取user到后端
    //再到服务层（虽然不理解为什么非要多加一个服务层），服务层调用持久层
    //Dao的方法然后prep.setString(1, user.getUserId());由
    //user类型的get方法即user.getUserId()获取刚刚传入进来的user对象，再转为预编译对象
    //这样书写任何一个测试方法，就可以
        public Object saveUser(HttpServletRequest request) throws Exception{
            String userId = request.getParameter("userId");
            String password = request.getParameter("password");
            String userName = request.getParameter("userName");
            Integer userSex = Integer.parseInt(request.getParameter("userSex"));
            String userImg=request.getParameter("userImg");
            User user=new User(userId,password,userName,userSex,userImg,null);
            int n = userService.saveUser(user);
            return n;
        }
        public Object getUserByIdByPass(HttpServletRequest request) throws Exception {
            String userId = request.getParameter("userId");
            String password = request.getParameter("password");
            User user = userService.getUserByIdByPass(userId, password);
            return user;
        }
        public Object getUserById(HttpServletRequest request) throws Exception {
            String userId = request.getParameter("userId");
            User user = userService.getUserById(userId);
            return user;

        }
}
